package com.woniuxy.log;

import org.springframework.cglib.proxy.InvocationHandler;
import org.springframework.cglib.proxy.Proxy;

import java.lang.reflect.Method;

//代理类
public class Log{
    public Object craatFactory(Object obj){
        Object o = Proxy.newProxyInstance(obj.getClass().getClassLoader(), obj.getClass().getInterfaces(), new InvocationHandler() {
            @Override
            public Object invoke(Object o, Method method, Object[] objects) throws Throwable {
                //前置增强
                System.out.println("前置增强");
                //通过反射动态实现目标方法的执行
                Object invoke = method.invoke(obj, objects);
                //后置增强
                System.out.println("后置增强");
                return invoke;
            }
        });
        return o;
    }
}
